/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.sistemas.bc;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.cip.esymons.sistemas.be.SisGaleria;

/**
 *
 * @author WILLIAM
 */
@Stateless
public class SisGaleriaFacade implements SisGaleriaFacadeLocal {
    @PersistenceContext(unitName = "org.cip.esymons-ejbPU")
    private EntityManager em;

    public void create(SisGaleria sisGaleria) {
        em.persist(sisGaleria);
    }

    public void edit(SisGaleria sisGaleria) {
        em.merge(sisGaleria);
    }

    public void remove(SisGaleria sisGaleria) {
        SisGaleria aux = em.merge(sisGaleria);
        em.remove(aux);
    }

    public SisGaleria find(Object id) {
        return em.find(SisGaleria.class, id);
    }

    public List<SisGaleria> findAll() {
        return em.createQuery("select object(o) from SisGaleria as o order by o.galCategoria, o.galNombre ").getResultList();
    }

    public List<SisGaleria> findRange(int[] range) {
        Query q = em.createQuery("select object(o) from SisGaleria as o");
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        return q.getResultList();
    }

    public int count() {
        return ((Long) em.createQuery("select count(o) from SisGaleria as o").getSingleResult()).intValue();
    }

}
